import Vue from 'vue'
import Router from 'vue-router'
import MenuType from '@/utils/menuType'
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading
/* layout */
import Layout from '../views/layout/Layout'

const _import = require('./import_' + process.env.NODE_ENV)
Vue.use(Router)

/**
 * icon : the icon show in the sidebar
 * hidden : if `hidden:true` will not show in the sidebar
 * redirect : if `redirect:noredirect` will not redirct in the levelbar
 * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
 * meta : `{ role: ['admin'] }`  will control the page role
 **/
export const constantRouterMap = [
  {name: '404', path: '/404', component: _import('/404'), hidden: true},

  {
    name: '欢迎',
    path: '/',
    component: _import('/home'),
    hidden: false,
    icon: 'dashboard',
    type: MenuType.Link
  },
  {
    name: '游戏',
    path: '/game',
    component: Layout,
    hidden: false,
    type: MenuType.Expandable,
    children: [
      {
        name: '迷宫',
        path: '/game/maze',
        component: _import('/game/maze'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '数独',
        path: '/game/sudoku',
        component: _import('/game/sudoku'),
        hidden: false,
        type: MenuType.Link
      }
    ]
  },
  {
    name: '排序',
    path: '/sort',
    component: Layout,
    hidden: false,
    type: MenuType.Expandable,
    children: [
      {
        name: '冒泡排序',
        path: '/sort/bubble',
        component: _import('/sort/bubble'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '选择排序',
        path: '/sort/selection',
        component: _import('/sort/selection'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '计数排序',
        path: '/sort/count',
        component: _import('/sort/count'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '快速排序',
        path: '/sort/quick',
        component: _import('/sort/quick'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '插入排序',
        path: '/sort/insert',
        component: _import('/sort/insert'),
        hidden: false,
        type: MenuType.Link
      },
      {
        name: '桶排序',
        path: '/sort/bucket',
        component: _import('/sort/bucket'),
        hidden: false,
        type: MenuType.Link
      },
      // {
      //   name: '测试',
      //   path: '/sort/test',
      //   component: _import('/sort/test'),
      //   hidden: false,
      //   type: MenuType.Link
      // },
      {
        name: '猴子排序',
        path: '/sort/bogo',
        component: _import('/sort/bogo'),
        hidden: false,
        type: MenuType.Link
      }
    ]
  }
]

const router = new Router({
  base: `${process.env.customDir}`,
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})
router.routes = constantRouterMap
/**
 * 路由配置
 * @type {Object}
 */
/**
 * push到指定的路由
 * @param  {String | Object} key   路由配置键
 * @param  {*} param 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.pushTo = function (key, param, breadcrumb) {
  // this.push(this.routesConfig.getRoute(key, param, breadcrumb))
}
/**
 * replace到指定的路由
 * @param  {String | Object} key   路由配置键
 * @param  {*} param 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.replaceBy = function (key, param, breadcrumb) {
  // this.replace(this.routesConfig.getRoute(key, param, breadcrumb))
}
/**
 * push到指定的带query路由
 * @param  {String | Object} key   路由配置键
 * @param  {Object} query 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.pushQueryTo = function (key, query, breadcrumb) {
  // this.push(this.routesConfig.getRouteWithQuery(key, query, breadcrumb))
}
/**
 * replace到指定的带query路由
 * @param  {String | Object} key   路由配置键
 * @param  {Object} query 参数
 * @param  {String | Array} breadcrumb 自定义面包屑
 */
router.replaceQueryBy = function (key, query, breadcrumb) {
  // this.replace(this.routesConfig.getRouteWithQuery(key, query, breadcrumb))
}


export default router

export const asyncRouterMap = [
  {path: '*', redirect: '/404', hidden: true}
]
